<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="申请类型">
              <a-input v-model="queryParam.type" placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item label="选择时间:" labelAlign="left">
              <a-range-picker
                v-decorator="['range-time-picker']"
                show-time
                valueFormat="YYYY-MM-DD HH:mm:ss"
                @ok="confirmDate"
              />
            </a-form-model-item>
          </a-col>
          <a-col :md="6" :sm="45" :push="2">
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table">
      <s-table
        ref="table"
        size="default"
        :rowKey="record => record.id"
        bordered
        :columns="columns"
        :data="loadData">
        <span slot="type" slot-scope="text, record">{{ record.type == 1 ? '研究者 ' : '受试者' }}</span>
        <span slot="createTime" slot-scope="text, record">{{ record.createTime | moment }}</span>
        <span slot="status" slot-scope="text, record">{{ record.status | filtersState }}</span>
        <span slot="operation" slot-scope="text, record">
          <a @click="watchPayDetail(record)">查看</a>
        </span>
      </s-table>
    </div>
  </div>
</template>
<script>
import { getListAuditComplete } from '@/api/cost/cost'
export default {
  components: {},
  data () {
    return {
      // tab切换时，更改queryParams中的状态字段。
      queryParam: {
        status: 2
      },
      loadData: parameter => {
        console.log('loadData.parameter', parameter)
        return getListAuditComplete({ ...parameter, ...this.queryParam }).then(res => {
          return res
        })
      },
      advanced: false,
      columns: [
        {
          title: 'ID',
          dataIndex: 'id'
        },
        {
          title: '申请类型',
          dataIndex: 'type',
          scopedSlots: { customRender: 'type' }
        },
        {
          title: '申请备注',
          dataIndex: 'applyReason'
        },
        {
          title: '申请金额',
          dataIndex: 'totalAmount'
        },
        {
          title: '申请时间',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' }
        },
        {
          title: '当前状态',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ]
    }
  },
  mounted () {},
  methods: {
    // 查看某一个单号的付款详情
    watchPayDetail (e) {
      this.$router.push({
        name: 'suditingDetail',
        query: {
          id: e.id
        }
      })
    },
    // 时间选择器
    confirmDate (e) {
      console.log(e)
      this.queryParam.beginData = e[0]
      this.queryParam.endData = e[1]
    }
  },
  filters: {
    filtersState (val) {
      if (val === 1) {
        return '待提交'
      } else if (val === 2) {
        return 'PI待审核'
      } else if (val === 3) {
        return 'PI已驳回'
      } else if (val === 4) {
        return 'PM待审核'
      } else if (val === 5) {
        return 'PM已驳回'
      } else if (val === 6) {
        return '待支付'
      } else if (val === 7) {
        return '保税中'
      } else if (val === 8) {
        return '已完成'
      }
    }
  }
}
</script>
<style>
.top-tab {
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  margin-bottom: 40px;
}
.active-class {
  border-bottom: 3px solid #3c92ff;
  font-size: 18px;
}
.normal {
  font-size: 18px;
}
</style>
